Skip to content

Conversation

frsnn
Copy link

@frsnn frsnn commented Sep 5, 2025

Summary

Expose MouseCursor in the public API and move set_mouse_cursor() to the public WindowAdapter trait, so custom backends can set the cursor.

Changes

  • Move MouseCursor into internal/common/enums (now exported via items module)
  • Add set_mouse_cursor() to WindowAdapter trait
  • Add Window::set_mouse_cursor wrapper
  • Update backends (TestingWindow, WinitWindowAdapter)
  • Update imports (MouseCursor is now used via crate::items)
  • Remove old duplicate definitions

Notes

Closes #3905

Usage

use slint::{Window, MouseCursor};

let win = Window::default();
win.set_mouse_cursor(MouseCursor::Pointer);

Move MouseCursor into internal/common/enums and export via items module
Add set_mouse_cursor to WindowAdapter trait
Add Window::set_mouse_cursor wrapper
Update imports
Closes slint-ui#3905
@CLAassistant
Copy link

CLAassistant commented Sep 5, 2025

CLA assistant check
All committers have signed the CLA.

autofix-ci bot and others added 3 commits September 5, 2025 01:35
- Fix slint-docsnapper headless.rs implementation
- Fix i-slint-backend-qt qt_window.rs implementation
- Move set_mouse_cursor from WindowAdapterInternal to WindowAdapter trait
- Resolves build errors in CI/CD pipeline
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Could you please try to cleanup the patch to avoid unrelated change.
Also remove the Window::set_mouse_cursor API, as this is not how one should set a cursor to the window. (It is anyway going to be overridden by the internals)

Forward,
}

/// This enum represents different types of mouse cursors. It's a subset of the mouse cursors available in CSS.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't need to be moved. Makes the patch harder to review.

/// This enum represents different types of mouse cursors. It's a subset of the mouse cursors available in CSS.
/// For details and pictograms see the [MDN Documentation for cursor](https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#values).
/// Depending on the backend and used OS unidirectional resize cursors may be replaced with bidirectional ones.
enum MouseCursor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enum needs to be #[non_exhaustive] for compatibility with potential future cursor.

Comment on lines +711 to +714
/// Sets the mouse cursor for this window.
pub fn set_mouse_cursor(&self, cursor: crate::items::MouseCursor) {
self.0.window_adapter().set_mouse_cursor(cursor);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API shouldn't need to be there.
In order to set a mouse cursor on the window, one would use a TouchArea with a mouse-cursor property.

KeyEventResult, MouseEvent,
};
use crate::item_rendering::{CachedRenderingData, ItemRenderer};
use crate::items::MouseCursor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(a bit inconsistent to have some import through crates::items and some through super)

use crate::items::MouseCursor;

#[test]
fn test_mouse_cursor_api() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test, but maybe it could be in a module related to mouse cursor (items or platform) this tests.rs module is actually about API used by the tests but not the tests themselves.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated file

- Add #[non_exhaustive] attribute to MouseCursor enum for future compatibility
- Add exhaustive pattern matching with wildcard fallback in Winit backend
- Add exhaustive pattern matching with wildcard fallback in Qt backend
- Ensures compilation with non-exhaustive enum variants

Addresses all maintainer feedback from PR review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow custom backends to set the mouse cursor
3 participants